﻿<?php
require_once('mainstance.php');
$smarty->assign("s1","register");
$smarty->assign("nawig1",array("nazwa" => "Rejestracja","url" => "./register.php"));
$klient = new Klient();

if(isset($_POST) && count($_POST)){
	$p_imie='';$p_nazwisko='';$p_login='';$p_pass='';$p_email='';
	if(isset($_POST['imie']))$p_imie=$_POST['imie'];
	if(isset($_POST['nazwisko']))$p_nazwisko=$_POST['imie'];
	if(isset($_POST['login'])){$p_login=$_POST['login'];}
	else header('Location: ./register.php?action=failed&k=error_login_empty');
	if(isset($_POST['pass']) && isset($_POST['pass2'])){
		if($_POST['pass'] != $_POST['pass2']){
			header('Location: ./register.php?action=failed&k=error_pass_its_no_same');
		}
		$p_pass=md5($_POST['pass']);
	}
	if(isset($_POST['email']))$p_email=$_POST['email'];
	
	if($users->zarejestrujKlient($p_imie,$p_nazwisko,$p_login,$p_pass,$p_email)){
		header('Location: ./index.php?action=success');
	}else{
		header('Location: ./register.php?action=failed');
	}
}
if(isset($_GET['action'])){
	switch ($_GET['action']) {
		case 'failed':
		
			if(isset($_GET['k'])){
				if($_GET['k'] == 'error_login_empty'){
					$smarty->assign("komunikat","Brak logina");
				}else if($_GET['k'] == 'error_pass_empty'){
					$smarty->assign("komunikat","Brak hasła");			
				}else if($_GET['k'] == 'error_pass_its_no_same'){
					$smarty->assign("komunikat","Nieprawidlowe podane hasła");
				}else{
					$smarty->assign("komunikator","Wstąpił błąd");
				}
			}else{
				$smarty->assign("komunikat","Wstąpil błąd");
			}
			
			break;
		case 'success':
			$smarty->assign("komunikat","Pomyslnie zakonczono");
			break;

	}
}
$smarty->display('templates/index.tpl');
?>